﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="find_class.aspx.cs" Inherits="SQT.tracnghiem.Ajax.ASP.Class.find_class" %>

<%@ Import Namespace="DataAccess" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<body>
    <tr class="w3-teal">
        <th>Lớp</th>
        <th>Giáo viên</th>
        <th>Ngày khai giảng</th>
        <th>Ngày tốt nghiệp</th>
        <th>Hình thức</th>
        <th>Lịch học</th>
        <th>Sáng</th>
        <th>Chiều</th>
        <th>Tối</th>
        <th>Trình độ</th>
        <th>Bài học</th>
    </tr>
    <% 
        string str = Request.QueryString["str"].ToLower();
        var get_cls = (from p in new TblClassController().FetchAll() orderby p.Id descending where p.ClassName.ToLower().Contains(str) select p);
        foreach (TblClass cls in get_cls)
        {
            if (cls.Id == 0)
                continue;
            var get_teacher = new TblManagerController().FetchAll().Where(x => x.ManagerId == cls.Teacher).Single();

            string time = "";
            string temp = cls.Schedule;
            string[] split = new string[7];
            split = temp.Split(',');
            for (int i = 0; i < temp.Split(',').Length - 1; i++)
            {
                if (split[i] != "")
                {
                    int temp2 = int.Parse(split[i]) + 1;
                    if (temp2 == 1)
                        time += " Thứ 2";
                    else
                        time += " Thứ " + temp2;
                    if (split[i + 1] != "")
                        time += ",";
                }
            }

            string morning = "", afternoon = "", evening = "";
            temp = cls.TimeStudy;
            split = temp.Split(',');
            string[] split2 = new string[2];
            if (split[0] != "")
            {
                split2 = split[0].Split('_');
                morning = split2[0] + " - " + split2[1];
            }
            if (split[1] != "")
            {
                split2 = split[1].Split('_');
                afternoon = split2[0] + " - " + split2[1];
            }
            if (split[2] != "")
            {
                split2 = split[2].Split('_');
                evening = split2[0] + " - " + split2[1];
            }

            string open = "", close = "";
            if (cls.OpenDate != null)
                open = DateTime.Parse(cls.OpenDate.ToString()).Day + "/" + DateTime.Parse(cls.OpenDate.ToString()).Month + "/" + DateTime.Parse(cls.OpenDate.ToString()).Year;
            if (cls.CloseDate != null)
                close = DateTime.Parse(cls.CloseDate.ToString()).Day + "/" + DateTime.Parse(cls.CloseDate.ToString()).Month + "/" + DateTime.Parse(cls.CloseDate.ToString()).Year;
    %>
    <tr class="class-options">
        <td class="class_id w3-hide"><%=cls.Id %></td>
        <td><%
           if (DateTime.Parse(cls.OpenDate.ToString()).Date > DateTime.Now)
           {%>
            <i title="Sắp mở" class="w3-tiny fa fa-circle w3-text-blue"></i>
            <%}
                       else
                       {
                           if (cls.Active == true)
                           { %>
            <i title="Đang mở" class="w3-tiny fa fa-circle w3-text-green"></i>
            <%}
                           else
                           {%>
            <i title="Đã đóng" class="w3-tiny fa fa-circle w3-text-red"></i>
            <%}
                       } %>&nbsp;<%=cls.ClassName %></td>
        <td><%=get_teacher.FullName %></td>
        <td><%=open%></td>
        <td><%=close %></td>
        <td><%=cls.Degree %></td>
        <td><%=time %></td>
        <td><%=morning %></td>
        <td><%=afternoon %></td>
        <td><%=evening %></td>
        <td><%=cls.ClsLevel %></td>
        <td><%=cls.Lesson %></td>
    </tr>
    <%} %>
</body>
</html>
